Since November 2009, O2 are no longer the sole distributor of the Apple iPhone, and so have opened up their tight grip on the handset and will now allow you to unlock your iPhone.
Yes, you can now legally network unlock your O2 iPhone without having to Jailbreak your handset. This means that you are free to use your iPhone on any network that you like and that you can enjoy all the latest iPhone updates without worrying that it will re-lock a previously Jailbroken handset.

You can unlock your Pay Monthly iPhone at anytime to use on any network, and the best part is that it’s totally free. You will of course still be responsible for the remainder of your contract.
Simply go to the O2 website to Unlock your Pay Monthly iPhone and fill in your details. You will need to wait up-to 14 days for O2 to respond.
You can unlock your Pay as You Go iPhone at anytime to use on any network, but it will cost you £15, and the 12 months free Internet access will be removed from your account.
Simply go to the O2 website to Unlock your Pay as You Go iPhone and fill in your details. You will need to wait up-to 14 days for O2 to respond.
You will receive a confirmation text from O2 to say that your iPhone has been unlocked. Although they say 14 days, my text arrived the day after I filled in the form on the O2 website!

Plug your iPhone into iTunes and you will receive the below message to say that your iPhone has been successfully unlocked.

Now that your iPhone has been unlocked by O2, you can place any SIM of your choice in your handset. If you have previously Jailbroken your iPhone, you may want to restore the iPhone OS to the latest Apple version (removing the jailbreak).
Although you have an unlocked iPhone, your iPhone will be missing the important network configuration settings for MMS & Internet. You may need to have a Google around to find these and manually enter them in Settings > General > Network > Cellular Data Network.

If want to use 3UK as your mobile provider like I did, then follow these instructions on how to get a 3UK IPCC file onto your handset.