Futures contracts become physically deliverable or cash settled upon expiration. Gold is a physically deliverable contract.
There two two very important dates for traders:
First notice date - this is the date on which the counterparty to your contract can request delivery. Unless you are involved in the physical production/consumption of the commodity, most traders avoid this trading period. There is a lot of additional paperwork and costs required to avoid physical delivery and most futures brokers will automatically keep you away from this period anyway.
Last trading date - this is the last date on which trading can occur on the exchange.
Where do you find this information? It's in the contract specifications and trading rules published by the exchange.
For gold, the first notice date is determined by:
http://www.cmegroup.com/rulebook/NYMEX/1/7.pdf
"The first day during which an Assignment Notification can be issued shall be the last business day of the month prior to the delivery month and shall be referred to as “First Notice Day”
In the case of Gold, last trading date is determined by:
http://www.cmegroup.com/rulebook/NYMEX/1a/113.pdf
"No trades in Gold futures deliverable in the current month shall be made after the third last business day of that month"
To determine business days you'll need a trading holiday calendar.
It's possible to do all of this algorithmically - however, it's quite a job doing this across many markets with differing holidays.
CME publish their holiday schedule here:
http://www.cmegroup.com/tools-information/holiday-calendar.html
Note that trading holidays vary by market. For example, some futures will trade on certain holidays.