You Buy a contract from O2 (or whoever you are going with) you get a new number
You request a PAC Code from T-Mobile. This is usually sent by Text
You have 2 choices you can do this about 2 weeks before you get the phone and have the Code to take to whichever network you go to and the number is changed within a couple of days.
Or you can Buy a new contract from O2,Voda etc and then there is an option online to enter the PAC Code ( or ring customer services ) and then the number swaps over within a couple of weeks.
I did the Second when my wife went from Voda to O2 and the whole process took a week (3 days to get PAC and 4 Days for O2 to change the number over)
You may get fobbed off by T-Mob saying they dont have to give it you. It is a legal requirement that if you ask for it they have to release it to you so dont take no for an Answer