I invited Mary out for a meal, but unfortunately she had already had dinner.
why did use : had already had ?
Dorrah Saadwhy did use : had already had
To show that the dinner was the first of two events in the past.

1. Mary had dinner
2. I invited Mary

Because you are speaking about past and having the dinner has occurred for Mary on the more past time.
 CalifJim's reply was promoted to an answer.