Can I still use a tax free exchange if I purchase the replacement piece first?

In most cases, yes. This would be a “reverse exchange”. As long as the requirements of Internal Revenue Code Section 1031 are satisfied, especially with regard to timing and money flow, 1031 Exchanges can be either a forward exchange (sell then buy) or a reverse exchange (buy then sell).