To implement a custom logic using zip code entered by the customer with external api in checkout

I have store and each product in the store may be shipped from different location, I need to have a custom logic during checkout or just before checkout by collecting customers zipcode and and comparing it with product zipcode such that to calculate the distance and if its above a certain miles , I should have to restrict the customer from checkout and show them a message that this could not be done