The death of his father, Dom Luiz de Mello, drove him early to soldiering, and having joined a contingent for the Flanders war, he found himself in the historic storm of January 1627, when the pick of the Portuguese fleet suffered shipwreck in the Bay of Biscay. He spent much of the next ten years of his life in military routine work in the Iberian Peninsula, varied by visits to the court of Madrid, where he contracted a friendship with the Spanish poet Quevedo and earned the favor of the powerful minister Olivares. In 1637 the latter despatched him in company with the conde de Linhares on a mission to pacify the revolted city of Évora, and on the same occasion the duke of Braganza, afterwards King John IV (for whom he acted as confidential agent at Madrid), employed him to satisfy Philip III of Portugal of his loyalty to the Philippine Dynasty.