Try not to buy a used iPhone that comes from a carrier. There's a potential for the phone to be blacklisted even after the sale.
Your best bet is to look for a phone that was purchased unlocked directly from Apple, or buy a refurbished unit directly from Apple.