"Perhaps that is why AT&T gave me (free) the unlock code "
AT&T's official policy was that they would give any customer the unlock code IF the customer's account was more than 90 days old. Then they started some BS about "only if the phone
has been available for sale
for more than one year" regardless of account age. And now, supposedly, they are back to "if you've been a customer more than xx days...".
Bottom line, call a rep to ask about the current
policy and ask again if the rep says no. They usually take 48 hours to call back or email
and give you the code, they don't (didn't) provide it right away.
And some phones won't accept the unlock code unless there is an "alien" SIM card in them at the time it is entered.