Ya sure you can purchase phone from AT&T and use it with t-mobile sim only after unlocking the phone from AT&T ...You can easily unlock the phone using network unlock code ...You can purchase code from sites like Mobile-Unlocker.com here they are rendering network unlock code for all mobile models at reliable cost .You first check that whether the code is available for your mobile model ,country and network provider .If yes then pay for it and unlock your phone the cost to unlock the phone depends on the network provider with which your phone is locked at present ...