Translated by Muhammad Elshinawy
In the name of Allah, the Most Merciful, the Bestower of Mercy
وَعَسَىٰ أَن تَكْرَهُوا شَيْئًا وَهُوَ خَيْرٌ لَّكُمْ ۖ وَعَسَىٰ أَن تُحِبُّوا شَيْئًا وَهُوَ شَرٌّ لَّكُمْ ۗ وَاللَّـهُ يَعْلَمُ وَأَنتُمْ لَا تَعْلَمُونَ
But perhaps you hate a thing and it is good for you; and perhaps you love a thing and it is bad for you. And Allah Knows, while you know not. [Surat al-Baqarah: 216]
The great imam Ibn al-Qayyim (may Allah bestow mercy upon him) said,
“You should busy yourself doing what has been demanded of you, not what has been guaranteed for you. Provision and Death are two matters that are destined and finalized; so long as the time of death does not arrived, the provision will continue to come.”
And if Allah closes one of its paths for a wisdom which He alone knows, He will – out of His mercy – open another path for you which is even more beneficial.
Ponder the state of the embryo, how it is fed from the blood of the mother through one path; the umbilical cord. Once it is born and that path is closed, two other paths – the breasts – are opened for him through which nourishment is now provided, except that it’s more delicious than what he used to receive from the first path. Thereafter, these two paths are closed upon weaning the child, but four paths of nourishment replace them which are more perfect for the human being; two food (animal and vegetation) and two drink (water and milk). Eventually, these four paths are also closed by a person dying. However, Allah will open – if he is an inhabitant of Paradise – eight paths in their stead; the eight gates of Paradise, to enter from whichever of them he pleases.
In this fashion, Allah does not prevent His slave from attaining any worldly matter, except to give him something better and more beneficial than it. No one enjoys this privilege except the believer; Allah deprives him of acquiring the lower in order to grant him the higher. But due to man’s ignorance of what is actually good for him, and the wisdom, generosity, and kindness of his Creator, he isn’t able to differentiate between what he has been prevented from and what has been preserved for him. On the contrary, he is deeply attracted to the immediate things, even if they may be inferior, and hardly yearns for what has been deferred for him, even if they are superior.
If man were just with his Creator – he is not so – he would realize the favor of Allah on him via the worldly enjoyment that He deprived him of, and it being far greater than what He gave him of its enjoyment. Indeed, He only deprived him in order to give him, and He only afflicted him in order to heal him, and He only tested him to strengthen his bond with his Creator, and He only put him to death in order to elevate him, and He only removed him from this worldly life in order to meet Him.”
 Taken from [al-FawâEid], by Ibn al-Qayyim, with adaption.