This is exactly what I had to do back in February. I accepted a job offer just to get me out of where I was. It paid the same money but was 20 miles per day extra travelling. I then heard about a job going at a place virtually on my doorstep paying 5k more and less hours too. I applied for it. Then whilst waiting for the outcome of the interview, the contract came through for the first job. I delayed sending it back by a week and then the offer came through for the second job, which I accepted. I then apologised to the first company and explained that I had received a better offer.
You have to look after number 1 at the end of the day.
Good luck with everything.