Hello Govardhan
The BGP attributes path selection process is something that has been defined based on designed and extensive testing performed by engineers over the past few decades. In this process, the Origin Type attribute is checked before the MED attribute, and for good reason.
The origin attribute indicates how BGP learned the route, which is generally considered to be more important than the MED attribute.
The origin code tells you if the route was learned from an IGP, EGP, or if it was incomplete. This attribute can provide significant information about the trustworthiness of the route because it indicates the origin of the route, or how the route was learned.
On the other hand, the MED (or Multi-Exit Discriminator), also sometimes referred to as the āmetricā is an optional, non-transitive attribute that is usually manually set, that is used for informing external neighbors about the preferred path into an AS when multiple entry points exist. The MED can be thought of as a āhintā to external neighbors about the preferred path, but it is not always honored by all routers.
So, in essence, the origin code is usually checked before the MED because it provides what is considered to be more crucial and trustworthy information about the routeās origin, which is often more important to determine the preferred path. Does that make sense?
I hope this has been helpful!
Laz