Start with the bank where you have your checking and savings account. They can streamline some of the paperwork, because they can see how much you make, and have access to several years worth of bank statement.
Legitimate mortgage companies do publish their rates. But there is no guarantee that you will qualify for the best rate without them knowing your credit score, salary, and down payment information.
There is no way to know that you have the best rate because of the time lag involved. You will pick the best one you can work with, but the rates can change every day. Even when you lock in the rates, other companies can drift lower. Once you have started down the application process you will reach a point where switching companies will cost you time and money.
Once you decide to purchase a house, the contract usually only gives you a few weeks to prove that you have financing in place. Therefore you will have to start the process before deciding on the house. Some advance work is needed to give you an idea of the maximum monthly payment you can afford, which will then based on the rate and down payment determine the maximum house you can buy.
I have had good luck with my credit union, but there is no guarantee that yours will be competitive. Keep in mind that while rates are very important, some people also value customer service, and also like that the mortgage won't be sold to out of town investors.