First you need to Install Itunes. which is available to download for free at
http://www.apple.com/itunes/download/
Then plug in your Iphone with the Dock and then open Itunes.. Make sure Itunes Detects your Iphone..
ITunes would then ask you to Activate you Iphone through the internet. If you going to be starting a new contract then go to
http://support.apple.com/kb/HT1603?locale=en_GB for a complete guide.
If you looking at getting it unlocked.... your in the right place!
After installing, depending on the Version you have iTunes will ask you to update the software, (this is free through iTunes) and will be on the main screen on you Itunes, Iphone menu. Just by clicking Update, Itunes would literally do the rest.
After the update is complete you would get this screen on the Iphone.

Then Change the sim to the your Sim. This is quite tricky so check out this link. It was very useful for me.
http://www.youtube.com/watch?v=kir19QRGzv8
Then Download ZiPhone from
http://download.ziphone.org/

After downloading it. Install it and Run the ZiPhoneGUI.EXE . You should get a screen like this

All you have to do is make sure your Sim card is in the Iphone, The Iphone is connected to the computer and then click on "Do it all" this will literally do everything for you and your Iphone would be unlocked and ready to use on your Network.
After Your Iphone has been unlocked, depending on the network you may have to do some changes to get access to internet, GPRS and Edge. The next link will give you the APN settings. To change settings go to
Settings>General>Network>Edge
http://www.taniwha.org.uk/gprs.html
this will give you the settings needed to use internet on the iphone
and finally (might be a bit stupid but could solve some problems) if you having trouble hearing the caller try removing the protective film cover. because i had this problem and was searching all over for a fix n then realized that it was because of this!
Hopefully you have got it all done..
One problem i still have is i cant connect to EDGE. I am guessing this is because T-Mobile UK dont have EDGE coverage (according to a T-mobile UK Customer Service Rep) . Still looking around to see if this info is right.