´It was narrated that 'Abdur-Rahman bin Samurah said:` "The Prophet said to me: 'If you swear an oath, and you see something that is better, then do that which is better and offer expiation for your oath.'"
Hadith Referenceسنن نسائي / كتاب الأيمان والنذور / 3820
Narrated Abdur-Rahman bin Samurah: The Prophet ﷺ said to me: Abdur-Rahman bin Samurah, when you swear an oath and consider something else to be better than it, do the thing that is beter and make atonement for your oath. Abu Dawud said: I heard Ahmad (b. Hanbal) permitting to make atonement before breaking the oath.
Shaykh Umar Farooq Saeedi
Benefits and Issues: If someone has taken an oath, but there is a Shari‘ah-based or moral benefit in acting contrary to it, then one should act upon the better course. And the expiation (kafarah) for the oath should be given. And there is flexibility in this matter: one may give the expiation before or after (breaking the oath).
Source: Sunan Abu Dawood – Commentary by Shaykh Umar Farooq Saeedi, Page: 3277