Purchase an unlocked phone from a legitimate source (i.e. Apple if they sell unlocked phones in your country or a carrier who sells unlocked phones. See this list: http://support.apple.com/kb/ht1937).
If you already have one, you should be able to call AppleCare and give them the serial number. They should be able to tell you if it's locked and who it's locked to.