Should you use a sole proprietorship, a partnership, an LLC or one of the different types of corporations as your business entity?
That is a question with significant ramifications in terms of both liability and taxation issues. Your personal situation and a number of factors concerning the design of your business and its financing will determine the correct answer. It is sometimes quite difficult to change the form of your entity later so you want to make sure you get this right in the beginning.
As to your question of timing, as a general rule the answer is probably the sooner the better once you know for sure exactly what you are going to be doing. Setting up an entity like a corporation or LLC usually involves some effort and expense on your part even if you're just using an internet site to assist you.
I wouldn't waste the time or money to do this before discovery day events or even applying for a loan since you aren't sure what franchise you're going to get or whether your loan will be approved.
On the other hand, once you know what you're going to do, make sure you set up your legal entity before signing significant contracts unless they have liberal assignment clauses. A franchise agreement is usually easy to transfer into your entity after the fact but a real estate lease for example may not be.
As a final note, be prepared to execute personal guarantees on all contracts if you want the contract to be in the name of your company. Most lenders, franchisors and landlords won't do it any other way.